package com.ryskoo.catering.productattrvalue.repository;

import com.ryskoo.catering.productattrvalue.domain.ProductAttrValuePO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductAttrValueJPAImpl extends BasicJPAImpl<ProductAttrValuePO> implements IProductAttrValueRepository{
    @Override
    public void deleteByAttrIds(List<String> attrIds) {
        String hql = "delete from ProductAttrValuePO o where o.attrUuid in (:attrUuid)";
        Query query = getH4Session().createQuery(hql);
        query.setParameterList("attrUuid", attrIds);
        query.executeUpdate();
    }

    @Override
    public List<ProductAttrValuePO> getValuesByAttrId(String attrId) {
        String hql = "from ProductAttrValuePO o where o.attrUuid = :attrId order by o.position asc";
        Query query = getH4Session().createQuery(hql);
        query.setString("attrId", attrId);
        return query.list();
    }
}
